package org.springboot.sample;

import org.springboot.sample.servlet.MyServlet1;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@ServletComponentScan
public class SpringBootSampleApplication {
	
	public static void main(String[] args) {
		SpringApplication.run(SpringBootSampleApplication.class, args);
	}
//	@Bean
//	public FilterRegistrationBean filterRegistrationBean(){
//		FilterRegistrationBean filter =  new FilterRegistrationBean(new MyFilter());
//		filter.addUrlPatterns("/*");
//		return filter;
//	}
//	@Bean
//	public ServletListenerRegistrationBean<EventListener> sessionListenerRegistrationBean(){
//		return new ServletListenerRegistrationBean<>(new MyHttpSessionListener());
//	}
//	@Bean
//	public ServletListenerRegistrationBean<EventListener> contextListenerRegistrationBean(){
//		return new ServletListenerRegistrationBean<>(new MyServletContextListener());
//	}
	
	/**
	 * 使用代码注册Servlet（不需要@ServletComponentScan注解）
	 * @return
	 */
	@Bean
	public ServletRegistrationBean servletRegistrationBean(){
		// ServletName默认值为首字母小写，即myServlet
		return new ServletRegistrationBean(new MyServlet1(),"/sv/*");
	}
	//疑问：会造成jsp页面无法访问
//	@Bean
//	public ServletRegistrationBean dispatcherRegistration(DispatcherServlet dispatcherServlet){
//		ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet);
//		registration.getUrlMappings().clear();
//		registration.addUrlMappings("*.do");
//		registration.addUrlMappings("*.json");
//		return registration;
//		
//	}
}
